<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
	<base href="/">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    <script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="js/xadmin.js"></script>

<style>
          .layui-form-item .layui-input-inline {
              width: 300px;
          }
      </style>
  </head>
  <body>
    <div class="x-body">
        <form class="layui-form" id="userForm">
            <input type="hidden" name="id" id="id">
            <input type="hidden" name="serviceName" id="serviceName">
           <!--
            <div class="layui-form-item">
                <label for="id" class="layui-form-label">
                    <span class="x-red">*</span>ID
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="id" name="id" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>-->


            <div class="layui-form-item">
                <label for="bookId" class="layui-form-label">
                    <span class="x-red">*</span>书本编号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="bookId" name="bookId" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="bookName" class="layui-form-label">
                    <span class="x-red">*</span>书名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="bookName" name="bookName" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="publishing" class="layui-form-label">
                    <span class="x-red">*</span>出版社
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="publishing" name="publishing" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="price" class="layui-form-label">
                    <span class="x-red">*</span>价格
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="price" name="price" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="author" class="layui-form-label">
                    <span class="x-red">*</span>作者
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="author" name="author" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="recommend" class="layui-form-label">
                    <span class="x-red">*</span>推荐理由
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="recommend" name="recommend" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>


          <div class="layui-form-item">
              <label for="" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  增加
              </button>
          </div>
      </form>
    </div>
    <script>
        $(function(){

            layui.use(['form','layer'], function(){
                form = layui.form,layer = layui.layer;
                var id=getQueryParam("id");
                if(typeof(id)!="undefined"&&id!=""){
                    //初始化页面数据
                    //根据用户id查询基本信息
                    //alert(id);
                    $.ajax({
                       contentType: "application/x-www-form-urlencoded",
                     //   url:'user_hystric/findStudentsById/'+id,
                        url:'http://localhost:9527/proxy/api-consumer/book_hystric/findBooksById/'+id+'?accessToken=2',
                        async:false,
                        success:function (res) {
                            if(res.code==200){
                                console.log("22="+res.data.user.stuName);
                                $("#id").val(res.data.user.id);
                                $("#bookId").val(res.data.user.bookId);
                                $("#bookName").val(res.data.user.bookName);
                                $("#publishing").val(res.data.user.publishing);
                                $("#price").val(res.data.user.price);
                                $("#author").val(res.data.user.author);
                                $("#recommend").val(res.data.user.recommend);
                                $("#serviceName").val(res.data.user.serviceName);
                            }else{
                                layer.msg(res.msg,{icon:5,time:1000});
                            }
                        },
                        error:function () {
                            layer.msg("加载数据失败",{icon:5,time:1000});
                        }
                    });

                }

                //监听提交
                form.on('submit(add)', function(data){
                    $.ajax({
                        contentType: "application/x-www-form-urlencoded",
                 //       url:'user_hystric/editStudent',
                        url:'http://localhost:9527/proxy/api-consumer/book_hystric/editBook/?accessToken=2',
                        type:'post',
                        data:$("#userForm").serialize(),
                        success:function (res) {
                            if(res.code==200){
                                layer.alert("添加成功", {icon: 6},function () {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //刷新父页面 去最后一页
                                    parent.initUserList(parent.$("#pages").val());
                                    //关闭当前frame
                                    parent.layer.close(index);
                                });
                            }else{
                                layer.alert(res.msg, {icon: 5,time:1000});
                            }
                        },
                        error:function (res) {
                            layer.msg("操作失败",{icon:5,time:1000});
                        }
                    });
                    return false;
                });

            });
        });
    </script>
  </body>
</html>